package com.weaver.smartext.core.parser;

import com.weaver.smartext.core.domain.TextAnalysis;
import org.apache.tika.Tika;
import org.apache.tika.exception.TikaException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * @Description: 解析父类
 * @title: Parser
 * @Author Star_Chen
 * @Date: 2023/3/31 14:59
 * @Version 1.0
 */
public interface Parser<T> {

    T parser(String path);

    T parser(File file);

    T parser(TextAnalysis textAnalysis);

    default T parser(){
        return null;
    }

    default String parseInputStream(InputStream inputStream) {
        Tika tika = new Tika();
        try {
            return tika.parseToString(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TikaException e) {
            e.printStackTrace();
        }
        return "";
    }
}
